package com.yun.zf.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yun.zf.common.admin.dto.pact.PactSearchResMo;
import com.yun.zf.common.admin.model.pact.PactInfoMo;
import com.yun.zf.common.admin.model.pact.PactSearchMo;
import com.yun.zf.common.app.domain.ZfPact;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 合同表 Mapper 接口
 * </p>
 *
 * @author cj
 * @since 2021-04-07
 */
@Mapper
public interface ZfPactMapper extends BaseMapper<ZfPact> {


    @Select("<script>" +
            "  SELECT p.id pactId, p.transaction_type,p.order_id,p.pact_type,p.pact_temp,p.amount,p.sign_agent,p.sign_name,p.dept_id, p.dept_name " +
            " ,p.final_price,p.price_unit,p.address,p.house_id,p.city_name,p.region_name,p.street_name,p.area,p.cert_type,p.cert_number,p.`owner`,p.is_dy " +
            "  from zf_pact p WHERE p.id=#{pactId}  and  p.city_code=#{cityCode} and  p.province_code = #{provCode}" +
            "</script>")
    public PactInfoMo getPactInfo(Long provCode, Long cityCode, Long pactId);



    @Select("<script>" +
            "   SELECT p.id pactId, p.transaction_type,p.order_id,p.pact_type,p.pact_status ,p.sign_name, p.dept_name ,p.address,p.house_id,p.create_time,p.pact_effect_time,p.pact_end_time from zf_pact p  WHERE  p.sign_agent=#{agentNo}  " +
            " <if test=\"search.startTime != null and search.startTime != ''  \"> and  unix_timestamp(create_time) >=unix_timestamp(#{search.startTime}) </if>" +
            " <if test=\"search.endTime != null and search.endTime != ''  \"> and  unix_timestamp(create_time) <![CDATA[ <= ]]> unix_timestamp(#{search.endTime}) </if>" +
            " <if test=\"search.pactStatus != null and search.pactStatus != '' \"> and  pact_status = #{search.pactStatus} </if> " +
            " <if test=\"search.pactId != null and search.pactId != '' \"> and  id = #{search.pactId} </if> " +
            "  and  p.city_code=#{cityCode} and  p.province_code = #{provCode}" +
            "</script>")
    public List<PactSearchResMo> searchPact(Long provCode, Long cityCode, @Param("search")PactSearchMo pactSearchMo, int agentNo, Page<PactSearchResMo> page);



}
